package chapte05.e8;

public class E9 {
    private static final int TIMES = 100000;

    public static void main(String[] args) {
        E9.testString();
        E9.textStringBuffer();
        E9.textStringBuilder();
    }
    public static void testString(){
        long startTime = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < TIMES; i++){
            str += "test";
        }
        long endTime = System.currentTimeMillis();
        System.out.println("String test usedtime:" + (endTime - startTime));
    }
    public static void textStringBuffer(){
        long startTime = System.currentTimeMillis();
        StringBuffer str = new StringBuffer();
        for (int i = 0; i < TIMES; i++){
            str.append("test");
        }
        long endTime = System.currentTimeMillis();
        System.out.println("StringBuffer test usedtime:" + (endTime - startTime));
    }
    public static void textStringBuilder(){
        long startTime = System.currentTimeMillis();
        StringBuffer str = new StringBuffer();
        for (int i = 0; i < TIMES; i++){
            str.append("test");
        }
        long endTime = System.currentTimeMillis();
        System.out.println("StringBuilder test usedtime:" + (endTime - startTime));
    }
}
